package com.sgb.kjwl.model.entity.enterprise;

import com.sgb.kjwl.model.entity.Bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class ServiceProjectClassEntity implements Serializable {


    /**
     * name : 1
     * no : 1630382404470
     * child : [{"name":"1.1","parentNo":1630382404470,"no":1630382408550},{"name":"1.2","parentNo":1630382404470,"no":1630382414023}]
     */


    public ServiceProjectClassEntity(String name){
        this.name = name;
        this.no = System.currentTimeMillis()+(long)(Math.random()*(100-1)+1);//自动生产id
    }

    /**
     * 填加子项
     * @param name
     */
    public boolean AddChildBean(String name){
        if(this.child.size()>0){
            for (ChildBean childBean : this.child) {
                if(name.equals(childBean.getName())){
                    return false;
                }
            }
        }
        return   this.child.add(new ChildBean(no, name));
    }

    /**
     * 更新子项
     * @param position
     * @param name
     * @return
     */
    public boolean upDateChildBean(int position,String name){
        if(this.child.size()>0){
            for (ChildBean childBean : this.child) {
                if(name.equals(childBean.getName())){
                    return false;
                }
            }
        }
        this.child.get(position).setName(name);
        return true;
    }

    private String name;
    private long no;
    private List<ChildBean> child = new ArrayList<>();


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getNo() {
        return no;
    }


    public void setNo(long no) {
        this.no = no;
    }

    public List<ChildBean> getChild() {
        return child;
    }

    public void setChild(List<ChildBean> child) {
        this.child = child;
    }

    public static class ChildBean implements Serializable {
        /**
         * name : 1.1
         * parentNo : 1630382404470
         * no : 1630382408550
         */

        private String name;
        private long parentNo;
        private long no;

        public ChildBean(long parentNo,String name){
            this.parentNo = parentNo;
            this.name = name;
            this.no = System.currentTimeMillis()+(long)(Math.random()*(100-1)+1);//自动生产id
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public long getParentNo() {
            return parentNo;
        }

        public void setParentNo(long parentNo) {
            this.parentNo = parentNo;
        }

        public long getNo() {
            return no;
        }

        public void setNo(long no) {
            this.no = no;
        }
    }
}
